Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slice function #250

Merged
merged 2 commits into from
Apr 21, 2015
Merged

Add slice function #250

merged 2 commits into from
Apr 21, 2015

Conversation

megawac
Copy link
Contributor

@megawac megawac commented Mar 19, 2015

This pretty much unifies the drop and take functions while adding a potentially useful function :)

@megawac
Copy link
Contributor Author

megawac commented Mar 19, 2015

In terms of LOC this is

+ 15 lines
- 35 lines

:D

@svozza svozza mentioned this pull request Apr 9, 2015
@vqvu
Copy link
Collaborator

vqvu commented Apr 17, 2015

Thanks @megawac!

Sorry for taking so long. I have a few minor comments.


Stream.prototype.take = function (n) {
if (n === 0) {
if (start < 0 || start >= end) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start < 0 should be treated as start === 0. Like how drop handles n < 0. Otherwise, slice(-1, Infinity) and drop(-1) won't the the same.

Also, add a

if (start === 0 && end === Infinity) {
    return this;
}

so that we can drop the if (n <= 0) check in drop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is drop(-1) supposed to do because this probably breaks it (there are no unit tests for drop or take with negative indices) Misread

@vqvu vqvu added this to the v2.5.0 milestone Apr 17, 2015
*/

Stream.prototype.take = function (n) {
var s = this.slice(0, n);
s.id = 'take:' + s.id;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this stuff important?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The s.id? No. It's mostly for debugging. No harm in leaving it though.

@vqvu
Copy link
Collaborator

vqvu commented Apr 17, 2015

Thanks. This looks good to me.

There's some talk of maybe changing the name of this transform to substream in #267 (unfortunately initiated by me), so we'll wait on that a bit before merging this.

@svozza
Copy link
Collaborator

svozza commented Apr 21, 2015

We should probably stick with slice if we want to make interop with Ramda easier, we'd just have to alias it otherwise.

@vqvu
Copy link
Collaborator

vqvu commented Apr 21, 2015

Sounds good.

vqvu added a commit that referenced this pull request Apr 21, 2015
@vqvu vqvu merged commit 3c00209 into caolan:master Apr 21, 2015
@megawac megawac deleted the slice branch April 21, 2015 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants